<template>
	<div class="app-container">
		<div class="content">			  
			  <el-form :model="form" :rules="rules" ref="form" label-width="160px" class="demo-ruleForm">
			    <el-form-item label="请输入原密码：" class="is-required pwd_codeintwp" prop='oldPassword' v-if="!vshow">
			      <div class="intwp">
			      	<el-input type="password" v-model="form.oldPassword" auto-complete="off" size='mini' class='moneyint' placeholder=""></el-input>
			      </div>
			      <p style="color: #999999;font-size: 12px;position: relative;top: -15px;">请输入6-18位数的原密码</p>
			    </el-form-item>
			    <el-form-item label="请输入新密码：" class="is-required pwd_codeintwp" prop='newPassword'>
			      <div class="intwp">
			      	<el-input type="password" v-model="form.newPassword" auto-complete="off" size='mini' placeholder=""></el-input>
			      </div>
			      <p style="color: #999999;font-size: 12px;position: relative;top: -15px;">请输入6-18位数的新密码（允许输入数字和字母）</p>
			    </el-form-item>
			    <el-form-item label="请再次输入新密码：" class="is-required" prop='newPassword2'>
			      <div class="intwp">
			      	<el-input type="password" v-model="form.newPassword2" auto-complete="off" size='mini' placeholder=''></el-input>
			      </div>
			    </el-form-item>
			    
			     <el-form-item>
			     	<el-button type="info" @click="$router.back(-1)" size='small'>取消</el-button>
				    <el-button type="primary" @click="submitgo('form')" size='small'>确定</el-button>
				 </el-form-item>
			  </el-form>
		</div>
	</div>
</template>

<script>
import Vue from 'vue'
const TIME_COUNT = 60;
export default{
	data(){
			var oldpas = (rule,value,callback)=>{
				var regx =  /^[a-zA-Z0-9]{6,18}$/;				
				if(!regx.test(value)){
					callback(new Error('请输入正确的原密码'));
				}else{
					callback();
				}
			};
			var oldpas2 = (rule,value,callback)=>{
				var regx =  /^[a-zA-Z0-9]{6,18}$/;				
				if(!regx.test(value)){
					callback(new Error('请输入正确格式的新密码'));
				}else{
					callback();
				}
			};
		  var validatePass = (rule, value, callback) => {
	        if (value === '') {
	          callback(new Error('请输入新密码'));
	          //this.show2=true
	        } else {
	          if (this.form.newPayPassword2 !== '') {
	            this.$refs.form.validateField('newPassword2');
	          }
	          else{
	          }
	          callback();
	        }
	      };
	      var validatePass2 = (rule, value, callback) => {
	        if (value === '') {
	          callback(new Error('请再次输入密码'));
	        } else if (value !== this.form.newPassword) {
	          callback(new Error('两次输入密码不一致!'));
	        }
	        else {
	          callback();
	        }
	      };
		return{
			vshow:false,
			phoneNumber:'-',
			form:{
				oldPassword:'',
				newPassword:'',
				newPassword2:'',
			},
			rules:{
				oldPassword:[{ required: !this.vshow, message: '请输入旧密码', trigger: 'blur' },
								{ validator: oldpas, trigger: 'blur' }],			
				newPassword:[{ validator: validatePass, trigger: 'blur' },
								{ validator: oldpas2, trigger: 'blur' }],
				newPassword2:[{ validator: validatePass2, trigger: 'blur' },],
			},
			show: true,
			show2: false,
			count: '',
      		timer: null,      		
		}
	},
	mounted(){
		this.isTrue();
	},
	watch:{

	},
//	filters: {
//      moneydou(val){
//      	val = val.toString().replace(/\$|\,/g,'');
//		    if(isNaN(val)) {
//		      val = "0";  
//		    } 
//		    let sign = (val == (val = Math.abs(val)));
//		    val = Math.floor(val*100+0.50000000001);
//		    let cents = val%100;
//		    val = Math.floor(val/100).toString();
//		    if(cents<10) {
//		       cents = "0" + cents
//		    }
//		    for (var i = 0; i < Math.floor((val.length-(1+i))/3); i++) {
//		        val = val.substring(0,val.length-(4*i+3))+',' + val.substring(val.length-(4*i+3));
//		    }
//		
//		    return (((sign)?'':'-') + val + '.' + cents);
//		},
//		hideMiddle(val) {
//          if(val && val!=''){
//          	return `${val.substring(0,3)}****${val.substring(val.length-4)}`;
//          }
//      }
//  },
	methods:{
//		isTrue(){
//			let params ={};
//			this.post(params,'services/app/applets/CheckEnterpriseSetPwd').then(res=>{
//				if (res.success) {
//					if (res.result.hadPwd==true) {
//						this.vshow = false;
//					} else{
//						this.vshow = true;
//					}
//					this.phoneNumber = res.result.smsPhoneNumber;
//				}else{
//					
//				}
//			})
//		},
//	    getnumber2() {
//	      console.log(this.show)
//	      if (!this.timer) {
//	        this.count = TIME_COUNT;
//	        this.show = false;
//	        this.getnumber3();
//	        this.timer = setInterval(() => {
//	          if (this.count > 0 && this.count <= TIME_COUNT) {
//	            this.count--;
//	          } else {
//	            this.show = true;
//	            clearInterval(this.timer);
//	            this.timer = null;
//	          }
//	        }, 1000)
//	      }
//	    },
//	    //第一个验证码发送
//	    getnumber3() {
//	      let params = {}
//	      this.post(params, 'services/app/applets/SendSMSCodePC').then(rs => {
//	        if (rs.success) {
//	        	this.form.securitycode = rs.result.securityCode;
//	        	this.$message({
//		          message: '验证码已发送，请注意查收',
//		          type: 'success'
//		        });
//	        }
//	      })
//	    },
	    submitgo(formName){
	    	let me = this;
	    	this.$refs[formName].validate((valid) => {
	          if (valid) {
	            let params = {
	            	oldPassword:this.form.oldPassword,
	            	newPassword:this.form.newPassword
	            };
	            
	            this.post(params, 'services/app/common/ResetPassword').then(res => {
	            	console.log(res)
			        if (res.success) {
	            		this.succeeNot();
	            		this.successLogin();
			        }
			    })
	          } else {
	            console.log('error submit!!');
	            return false;
	          }
	        });
	    },
	    successLogin(){
	    	 this.$store.dispatch("FedLogOut").then(res => {
	         console.log(res);
	         if (res == "success") {
	          this.$router.push({ path: "/login" });
          }
        });
	    },
//	    
	    
	    // 保存成功提示
	    succeeNot(){
	    	const h = this.$createElement;
	      	this.$notify({
	          title: '成功',
	          message: '密码设置成功',
	          type: 'success',
	          customClass:"el-notification-success"
	        });
	    },
	    //保存失败提示
	    // failNot(mes){
	    // 	//console.log(meaasge)
	    // 	const h = this.$createElement;
	    //   	this.$notify.error({
	    //       title: '错误',
	    //       message: mes,
	    //       customClass:"el-notification-error"
	    //     });
	    // }
	}
}
</script>

<style lang="scss" scoped>
	.content{
		padding: 80px 20px 30px 300px;
		a{
			color: #027dca;
		}
		.pwd_codeintwp{
			margin-bottom: 0;
			height: 66px;
		}
		.intwp{width: 300px;}
		
	}
	
</style>
<style type="text/css">
	.pwd_codeintwp .el-form-item__error{
		position: relative;top: -35px;
	}
</style>